/*
 *  rgs_shape.c
 *  RGS
 *
 *  Copyright 2008 Ivan Safrin.
 *
 *  This code is distributed under the LGPL license.
 *  You should have a copy of LGPL.txt distributed
 *  with the project, but if not you can get a copy
 *  at http://www.gnu.org/licenses/
 *
 */
 
#include "rgs_data.h"
#include "rgs_core.h"
#include "rgs_shape.h"

RGS_Shape *RGS_CreateShape(RGS_Screen *screen, short type, int color, short x, short y, short w, short h) {
	RGS_Shape *newShape;
	newShape = (RGS_Shape*)malloc(sizeof(RGS_Shape));
	memset(newShape, 0, sizeof(RGS_Shape));
	RGS_InitializeObject(&newShape->object, 0, 0);
	RGS_AddScreenObject(screen, (RGS_Object*)newShape);
	newShape->object.Render = RGS_RenderShape;
	newShape->object.x = x;
	newShape->object.y = y;
	newShape->object.w = w;
	newShape->object.h = h;
	newShape->type = type;
	
	RGS_Color tmp = RGS_SplitRGB(color);
	newShape->color = tmp;
	return newShape;	
}

void RGS_RenderShape(SDL_Surface *target, void *object) {
	RGS_Shape *shape = (RGS_Shape*)object;
	RGS_Rect rect;
	rect.h = shape->object.h;
	rect.w = shape->object.w;
	rect.x = shape->object.x;
	rect.y = shape->object.y;
				
	switch(shape->type) {
		case RGS_SHAPE_RECT:
			RGS_FillRect(&rect, shape->color.rgb);
		break;
		case RGS_SHAPE_RECT_OUTLINE:
			RGS_DrawLine(rect.x, rect.y, rect.x+rect.w, rect.y, shape->color.rgb);
			RGS_DrawLine(rect.x+rect.w, rect.y, rect.x+rect.w, rect.y+rect.h, shape->color.rgb);
			RGS_DrawLine(rect.x+rect.w, rect.y+rect.h, rect.x, rect.y+rect.h, shape->color.rgb);
			RGS_DrawLine(rect.x, rect.y+rect.h, rect.x, rect.y, shape->color.rgb);
		break;
		default:
		break;
	}
}